package com.bidianying.dao;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class TaobaoDao {
	
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	public int saveTaobaoCinemaInfo(List<Map<String,String>> list){
		final List<Map<String,String>> tempList = list;   
		String sql = "insert into tTaobao_cinema(cinemaName,cinemaId,address,telephone,href,cityPinyin) values(?,?,?,?,?,?)";
		int[] resultInt = jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter(){
			@Override
			public void setValues(PreparedStatement ps, int i)throws SQLException {
				ps.setString(1, tempList.get(i).get("cinemaName"));
				ps.setString(2, tempList.get(i).get("cinemaId"));
				ps.setString(3, tempList.get(i).get("limitAddress"));
				ps.setString(4, tempList.get(i).get("telephone"));
				ps.setString(5, tempList.get(i).get("href"));
				ps.setString(6, tempList.get(i).get("cityPinyin"));
			}
			@Override
			public int getBatchSize() {
				return tempList.size();
			}
		});
		return resultInt.length;
	}
	
	public int updateMovieInfoForTaobao(List<Map<String,String>> list){
		final List<Map<String,String>> tempList = list;   
		String sql = "update tMovie_info set taobaoMovieId=?,taobaoMovieName=? where id = ?";
		int[] resultInt = jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter(){
			@Override
			public void setValues(PreparedStatement ps, int i)throws SQLException {
				ps.setString(1, tempList.get(i).get("taobaoMovieId"));
				ps.setString(2, tempList.get(i).get("taobaoMovieName"));
				ps.setString(3, tempList.get(i).get("id"));
			}
			@Override
			public int getBatchSize() {
				return tempList.size();
			}
		});
		return resultInt.length;
	}
}
